package com.example.home.government.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.home.R;
import com.example.home.government.bean.MeAppealBean;

import java.util.List;

import static com.example.home.tool.StaticActi.ip;

public class MeAppealAdapter extends RecyclerView.Adapter<MeAppealAdapter.MyHoldy> {

    private Context context;
    private List<MeAppealBean.RowsBean> list;
    private View view;

    public MeAppealAdapter(Context context, List<MeAppealBean.RowsBean> list) {
        this.context = context;
        this.list = list;
    }


    @NonNull
    @Override
    public MyHoldy onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_general,null);
        return new MyHoldy(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyHoldy holder, int position) {
        //列表项信息包括标题、承办单位、提交时间和处理状态，未完结诉求优先顶部显示
        Glide.with(context).load(ip + list.get(position).getImgUrl()).into(holder.cover);
        Log.e("xhf","img=="+list.get(position).getImgUrl());
        holder.title.setText(list.get(position).getTitle());
        holder.content.setText(list.get(position).getUndertaker());
        String sta = list.get(position).getState();
        if ("0".equals(sta)){
            holder.contentNum.setText("未处理");
        }else if ("1".equals(sta)){
            holder.contentNum.setText("已处理");
        }
        holder.time.setText(list.get(position).getCreateTime());
    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

    public class MyHoldy extends RecyclerView.ViewHolder {
        ImageView cover;
        TextView title;
        TextView contentNum;
        TextView content;
        TextView time;
        public MyHoldy(@NonNull View itemView) {
            super(itemView);
            cover = itemView.findViewById(R.id.cover);
            content = itemView.findViewById(R.id.content);
            title = itemView.findViewById(R.id.title);
            contentNum = itemView.findViewById(R.id.contentNum);
            time = itemView.findViewById(R.id.time);
        }
    }
}
